<?php

namespace app\common\service\order\coupon_order\taobao;

use app\model\CouponOrder;
use app\model\MobileOrder;
use think\facade\Db;

class EleTaobao extends EleTaobaoBase
{
    public function syncOrder()
    {
        /**
         * @var CouponOrder $couponOrder
         */
        $couponOrder = $this->saveOrder();

        if (!$couponOrder) return;

        $changeStatusArr = [
            'status',
            'agent_settle_status',
            'refund_status',
            'profit',
            'platform_profit',
            'supplier_price',
            'pay_time',
            'pay_status',
            'product_name',
        ];

        foreach ($changeStatusArr as $value) {
            if ($this->{$value} != $couponOrder->{$value}) {
                $couponOrder->{$value} = $this->{$value};
                $couponOrder->log .= date('m-d H:i:s') . $couponOrder->{$value} . '=>' > $this->{$value};
                $couponOrder->save();
            }
        }


    }

    public function getServType()
    {
        return PRODUCT_ELE_SERV;
    }

    public function getProductName()
    {
        return $this->params['title']??'';
    }

    public function getProductImage()
    {
        return 'https://img.jutuike.com/taokeout/icon/ele.png';
    }

    public function getAgentSettleStatus()
    {
        $status = $this->params['settle_state'] ?? 2;  //结算状态，1-已结算 2-未结算
        if ($status == 1) {
            return CouponOrder::C_AGENT_SETTLE_STATUS_WAIT;
        }

        return CouponOrder::C_AGENT_SETTLE_STATUS_NO;
    }

    public function getStatus()
    {
        //0已失效，1已下单，2已付款，3售中退，4已收货，5售后退

        $status = $this->params['order_item_status'] ?? 0;

        if (in_array($status, [
            1, 2, 4
        ])) {
            return CouponOrder::C_STATUS_RECHARGE_SUCCESS;
        }
        return CouponOrder::C_STATUS_RECHARGE_FAIL;

    }

}